package com.sxz.sbs.view;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

/**
 * 自适应GridView
 */

public class SelfAdaptionGridView extends RecyclerView {
    public SelfAdaptionGridView(Context context) {
        this(context,null);
    }

    public SelfAdaptionGridView(Context context, AttributeSet attrs) {
        this(context, attrs,0);

    }

    public SelfAdaptionGridView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        this.setLayoutManager(new GridLayoutManager(context,3));
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //  AT_MOST参数表示控件可以自由调整大小，最大不超过Integer.MAX_VALUE/4
        int height= MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, height);
    }
}
